<?php
//Creating the browsefunction to browse through slides of art
$currentPage = (isset($_GET['currentPage']))?$_GET['currentPage']:0;//If variable is not already set, it is now!

if ($location != NULL){
    $locationUrl ="&location=$location";
}
if ($subCategory != NULL){
    $subCategoryUrl ="&subCategory=$subCategory";
}
if ($headCategory != NULL){
    $headCategoryUrl ="&headCategory=$headCategory";
}
if ($priceSort != NULL){
    $priceSortUrl ="&priceSort=$priceSort";
}







$nextPage = $currentPage +20;
$previousPage = $currentPage -20;



$font = '</font>';
if ($previousPage >= 0) {
echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $previousPage . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl. '">Föregående&nbsp;sida&nbsp;</a>&nbsp;|&nbsp;';
//If this link is pressed, $currentPage gets the value of $previousPage which result in that
//the previous Items from the databse is displayed
}
//if ($nextPage < $totalNumberOfItems) {
//echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $nextPage . $locationUrl. $subCategoryUrl. $headCategoryUrl.'">Nästa sida</a>';
//}
//End of browsefunction
//New updated function
if ($currentPage <= 60) {
            $page1 = 0;
            $page2 = 20;
            $page3 = 40;
            $page4 = 60;
            
            $linkNumber1 = 1;
            $linkNumber2 = 2;
            $linkNumber3 = 3;
            $linkNumber4 = 4;
if ($currentPage == 0)  {$activeLink1 = '<font color="orange">';}
if ($currentPage == 20) {$activeLink2 = '<font color="orange">';}
if ($currentPage == 40) {$activeLink3 = '<font color="orange">';}
//if ($currentPage == 72) {$activeLink4 = '<font color="red">';}


}
if ($currentPage >= 60){
            $page1 = $currentPage - 40;
            $page2 = $currentPage - 20;
            $page3 = $currentPage;
            $page4 = $currentPage + 20;
            $ix = ($currentPage -40)/20;

            $linkNumber1 = 1 +$ix;
            $linkNumber2 = 2 +$ix;
            $linkNumber3 = 3 +$ix;
            $linkNumber4 = 4 +$ix;

            $activeLink3 = '<font color="orange">';

            $backToPageOne = true;
}

//    $totalNumberOfItems = 10000;
//    For testing that the function works
if ($nextPage < $totalNumberOfItems) {

if ($backToPageOne == true){
echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=0' . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl.'">&nbsp;1..&nbsp;</a>';
}

echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $page1 . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl.'">'; print "$activeLink1&nbsp;$linkNumber1&nbsp;$font</a>";
echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $page2 . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl.'">'; print "$activeLink2&nbsp;$linkNumber2&nbsp;$font</a>";
if($totalNumberOfItems > 48){echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $page3 . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl.'">'; print "$activeLink3&nbsp;$linkNumber3&nbsp;$font</a>";}
if($totalNumberOfItems > 72){echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $page4 . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl.'">'; print "$activeLink4&nbsp;$linkNumber4&nbsp;$font</a>";}



echo '<a href="', $_SERVER['PHP_SELF'], '?currentPage=' . $nextPage . $locationUrl. $subCategoryUrl. $headCategoryUrl. $priceSortUrl.'">Nästa&nbsp;sida</a>';
}
?>